package cn.tedu._09interceptor.base.config;

import cn.tedu._09interceptor.base.interceptors.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    //addI + 回车
    public void addInterceptors(InterceptorRegistry registry) {
        //策略1:拦截所有请求;
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/*");
        //策略2:拦截指定的单个|多个请求,比如:拦截登录和注册两个功能,不拦截修改密码功能;
//         registry.addInterceptor(new MyInterceptor())
//                 .addPathPatterns("/v1/user/login","v1/user/reg");
        //策略3:拦截指定模块的所有请求,比如:拦截用户模块的所有功能;
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/user/**");
        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/user/**")
                .excludePathPatterns("/v1/user/login");
    }
}
